package com.zhiyu.controller;

import com.zhiyu.entity.VO.LoginFormVO;
import com.zhiyu.entity.VO.RegisterFormVO;
import com.zhiyu.entity.VO.ResponseVO;
import com.zhiyu.service.EncryptService;
import com.zhiyu.service.IndexService;
import com.zhiyu.util.JWTUtil;
import com.zhiyu.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.Request;

import javax.validation.Valid;

@RestController
public class IndexController {
    @Autowired
    private IndexService indexService;

    @Autowired
    private EncryptService encryptService;

    @Autowired
    private ResponseUtil responseUtil;

    @Autowired
    private JWTUtil jwtUtil;

    @RequestMapping(value = "/RSAPublicKey/{username}", method = RequestMethod.GET)
    public ResponseVO getRSAPublicKey(@PathVariable String username) {
        return encryptService.getRSAPublicKey(username);
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    public ResponseVO login(@Valid @RequestBody LoginFormVO loginFormVO) {
        return indexService.login(loginFormVO);
    }

    @RequestMapping(value = "/register", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    public ResponseVO register(@Valid @RequestBody RegisterFormVO registerFormVO) {
        return indexService.register(registerFormVO);
    }
}
